<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>002原生冒泡排序</title>
</head>
<body>
    <script>
        // 最外层的循环变量i只负责整体
        let arr = [5, 1, 9, 3, 8, 4, 4, 1]
        for(let i = 0; i < arr.length; i++) {
            for(let j = 0; j < arr.length - i; j++) {
                if(arr[j] > arr[j+1]) {
                    let temp = arr[j]
                    arr[j] = arr[j+1]
                    arr[j+1] = temp
                }
            }
        }
        console.log(arr)
    </script>
</body>
</html>